package com.hayrullah.cinema.Dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;

import com.hayrullah.cinema.Util.HibernateUtil;
import com.hayrullah.cinema.entity.Customer;

@SuppressWarnings("unchecked")
public class CustomerDao extends AbstractDao<Customer> {

	
	

	
	@Override
	public List<Customer> findAll() {
		List<Customer> customer = null;
		try {
			Session session = HibernateUtil.getSessionFactory()
					.getCurrentSession();
			session.beginTransaction();
			customer = (List<Customer>) session.createCriteria(Customer.class)
					.list();
			session.getTransaction().commit();
		} catch (HibernateException exception) {
			exception.printStackTrace();

		}
		return customer;
	}

	@Override
	public Customer findById(Long id) {
		Customer customer =null;
		try {
			Session session =HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			customer=(Customer) session.get(Customer.class, id);
			session.getTransaction().commit();
		} catch (HibernateException  exception) {
			exception.printStackTrace();
		}
		return customer;
	}

}
